import os
from py_files.pdf2md import imagePdfExtractor
from pdf_craft import LLM
from pdf_craft import analyse
from pdf_craft import generate_epub_file
from dotenv import load_dotenv
load_dotenv()
llm_key=os.getenv("llm_key")
llm_url=os.getenv("llm_url")
llm_model=os.getenv("llm_model")
llm_token_encoding=os.getenv("llm_token_encoding")

pdfcraft_llm = LLM(
  key=llm_key, # key provided by LLM vendor
  url=llm_url, # URL provided by LLM vendor
  model=llm_model, # model provided by LLM vendor
  token_encoding=llm_token_encoding, # local model name for tokens estimation (not related to LLM, if you don't care, keep "o200k_base")
)

pdf_path = "input_files/寒武纪2023合并资产负债表-图片式.pdf"
epub_analysing_dir_path="output_files/epub_analysing_dir"
epub_analyse_output_dir_path="output_files/epub_analyse_output_dir" #新任务可删除
epub_file_path="output_files/epub_output_dir/output.epub"

analyse(
  llm=pdfcraft_llm, # LLM configuration prepared in the previous step
  pdf_page_extractor=imagePdfExtractor, # PDFPageExtractor object prepared in the previous step
  pdf_path=pdf_path, # PDF file path
  analysing_dir_path=epub_analysing_dir_path, # analysing directory path
  output_dir_path=epub_analyse_output_dir_path, # The analysis results will be written to this directory
)


generate_epub_file(
  from_dir_path=epub_analyse_output_dir_path, # from the folder generated by the previous step
  epub_file_path=epub_file_path, # generated EPUB file save path
)